<?

if($_POST["selbox"] != ''){

	//reauth the user, if $_SESSION["reauthed"] != Y bail out
	if($check_me_authed == "OK"){

		$today_date 			= date("d-m-Y");

  	$srcDbHdr			     = "MST_MODEL";
    $srcDbHdrLog        = "LOG_MST_MODEL";
    $srcDbDtl           = "MST_MODEL_COMPOS";
    $srcDbSequence      = "MST_SEQUENCE";

    $UID     = unserialize($_SESSION["serUID"]);
    $userId  = $UID->getUID();

    $Db = new oracleDb;
    $Db->init($_SESSION["ORCL"],
               $_SESSION["OPASS"],
               $_SESSION["SID"],
               _NO_COMMENT);

    if($Db->connect()){

			if(sizeof($_POST["selbox"]) == 0){

				$Misc->usrDieJs("Error: nothing to be cancel");
			}else{

				foreach($_POST["selbox"] as $cclThisJobId){

					/**
      		* Fetch global header
      		* And check the status if it is valid
      		* where STATUS = _NOT_ACTIVE
      		*
      		*/
      		$CFetchers->fetchLstDataHeader($Db,
                                         $cclThisJobId,
                                         $srcDbHdr,
                                         $nHeader,
                                         $lstHeader);

					if($lstHeader["STATUS"][0] != _ACTIVE){

						$Misc->usrDieJs("Error: Tx with JobId: ".$cclThisJobId." is not yet approved.");
					}else{

						$CHandlers->procCancel($Db,
            						           $cclThisJobId,
            						           $userId,
            						           $srcDbHdr);

						/**
            * Extra work is to update the picked
            * jobId and check if recvQty
            * Greater than 0
            * YES: set status to _OUTSTANDING
            * NO : set status to _ACTIVE
            *
            */
            $isCancel   = true;
            $thisJobId  = $cclThisJobId;

            /**
            * Insert Log
            *
            */
            $CHandlers->insToDbLog($Db,
                                   $today_date,
                                   $cclThisJobId,
                                   $userId,
                                   $_SERVER["REMOTE_ADDR"],
                                   _CANCEL_MODE,
                                   $srcDbHdrLog);
					}

				}

				$Db->commit();

				if($Db->getStatus() == true){

      	  $Misc->usrMsg("Cancel Complete");
      	}else{

      	  $Misc->usrMsg("Cancel Process Interupted");
      	}

      	$Db->dc();

				//GoBack("2","../".$_SESSION["source_caller"]);
			}
		}else{

			$Misc->usrDieJs(_DB_CONN_ERROR);
		}
	}else{

		$Misc->usrDieJs("NOT AUTHED");
	}
}else{

  $Misc->usrDieJs("Error: No Selection");
}
?> 